package com.shilan.dllo.wangyi.adpter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.shilan.dllo.wangyi.entity.NewsEntity;
import com.shilan.dllo.wangyi.fragment.Headline_ad_fragment;

import java.util.List;

/**
 * Created by dllo on 15/10/28.
 */
public class Headline_ad_Adpter extends FragmentPagerAdapter{

    private  List<NewsEntity.T1348647853363Entity.AdsEntity> headline_ads;

    public Headline_ad_Adpter(FragmentManager fm) {
        super(fm);
    }

    public void addData(List<NewsEntity.T1348647853363Entity.AdsEntity> datas){
        headline_ads = datas;
        notifyDataSetChanged();
    }

    @Override
    public Fragment getItem(int position) {
        NewsEntity.T1348647853363Entity.AdsEntity ads =  headline_ads.get(position % headline_ads.size());
        String title = ads.getTitle();
        String imgsrc = ads.getImgsrc();

        return Headline_ad_fragment.getInstance(title,imgsrc);
    }

    @Override
    public int getCount() {
        return headline_ads != null && headline_ads.size()>0 ? Integer.MAX_VALUE : 0;
    }

}
